<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Link_library
{
	// Protected or private properties
	protected $_table;
	
	// Constructor
	public function __construct()
	{
		if (!isset($this->CI))
		{
			$this->CI =& get_instance();
		}
		
		$this->_table = $this->CI->config->item('database_tables');
	}
	
	// Public methods
	public function get_links($lang_id)
	{
		if($lang_id == null)
		{
			$lang_id = 2;// default language is vietnamese
		}
		$this->CI->db->select('*');
		$this->CI->db->where('status', 1);
		$this->CI->db->where('type', 1);
		$this->CI->db->where('lang_id',$lang_id); 
		$this->CI->db->order_by('id', 'ASC'); 
		$this->CI->db->limit($this->CI->system_library->settings['links_per_box']);
		
		$query = $this->CI->db->get($this->_table['link']);
		//var_dump($result = $query->result_array());
		if ($query->num_rows() > 0)
		{	
			$result = $query->result_array();
			
			foreach ($result as $key => $link)
			{
				$result[$key]['target']  = '_' . $link['target'];
			}
					
			return $result;
		}
	}
	public function get_banners($lang_id)
	{
		$limit = 5;//($this->CI->system_library->settings['banners_per_box'] != null)?$this->CI->system_library->settings['banners_per_box']:5;
		if($lang_id == null)
		{
			$lang_id = 2;// default language is vietnamese
		}
		$this->CI->db->select('*');
		$this->CI->db->where('status', 1);
		$this->CI->db->where('type', 2);
		$this->CI->db->where('lang_id',$lang_id);  
		$this->CI->db->order_by('link.order', 'DESC'); 
		$this->CI->db->limit($limit);
		
		$query = $this->CI->db->get($this->_table['link']);
		//var_dump($result = $query->result_array());
		if ($query->num_rows() > 0)
		{	
			$result = $query->result_array();
			
			foreach ($result as $key => $link)
			{
				$result[$key]['target']  = '_' . $link['target'];
			}
					
			return $result;
		}
	}
}

/* End of file Links_library.php */
/* Location: ./application/libraries/Links_library.php */